﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class active_HuluWaDrawAward_admin_index : System.Web.UI.Page
{
    public int total = 0, usercounts = 0;
    string connstr = "server=.;database=Activity_DB;uid=sa;pwd=zll;";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null || Session["user"].ToString().Length <= 0)
        {
            Response.Redirect("login.aspx");
            Response.End();
        }
        if (!this.IsPostBack)
        {
            DataTable dt = SqlHelper.ExecuteDataTable(connstr, CommandType.StoredProcedure, "Activity_Huluwa_BuildAwardData");
            reptDatas.DataSource = dt;
            reptDatas.DataBind();
            DataStatistics();
        }
    }

    private void DataStatistics()
    {


        try
        {
            DataTable dt = SqlHelper.ExecuteDataTable(connstr, CommandType.StoredProcedure, "[Activity_Huluwa_DataStatistics]");
            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                total = int.Parse(row[0].ToString());
                usercounts = int.Parse(row[1].ToString());
            }
        }
        catch (Exception ex)
        {
            string ss = ex.Message.ToString();
        }
    }


    protected void btnUpdateAll_Click(object sender, EventArgs e)
    {
        string ids = Request.Form["ids"];
        string[] arr = ids.Split(',');
        int minprop, maxprop;
        foreach (string item in arr)
        {
            minprop = Convert.ToInt32(Request.Form["minprop_" + item]);
            maxprop = Convert.ToInt32(Request.Form["maxprop_" + item]);
            SqlParameter[] p =
                    {
                         SqlHelper.MakeInParam("@id",SqlDbType.Int,4,Convert.ToInt32(item)),
                         SqlHelper.MakeInParam("@minprop",SqlDbType.Int,4,minprop),
                         SqlHelper.MakeInParam("@maxprop",SqlDbType.Int,4,maxprop)
                    };
            try
            {
                SqlHelper.ExecuteNonQuery(connstr, CommandType.StoredProcedure, "[Activity_Huluwa_UpdateAwardPropById]", p);
            }
            catch (Exception ex)
            {
                string ss = ex.Message.ToString();
            }
        }
        Response.Write("<script>alert('修改成功');window.location='index.aspx';</script>");
    }
}